package com.bridge.applets.strategy.handler.bridge;

import com.bridge.applets.model.entity.BridgeIdentifyCae;
import com.bridge.applets.model.entity.BridgeMonitorAnalysis;
import com.bridge.applets.model.entity.BridgeNeuralNetwork;
import com.bridge.applets.model.vo.req.BridgeAddReq;
import com.bridge.applets.utils.BridgeDataConvertUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class BridgeHandler {

    /**
     * 构建参数信息，通用里校验通用的，每个类型里校验每个类型里独有的参数
     * @param param
     * @return
     */
    public BridgeNeuralNetwork buildEntityNeuralNetwork(BridgeAddReq param){
        BridgeAddReq.NeuralNetworkData neuralNetwork = param.getNeuralNetwork();
        //校验构建 通用的信息
        BridgeNeuralNetwork entity=new BridgeNeuralNetwork();
        entity.setBridgeType(param.getBridgeType());

        entity.setGirderType(neuralNetwork.getGirderType());
        entity.setMainSpan(neuralNetwork.getMainSpan());
        entity.setMainBeamType(neuralNetwork.getMainBeamType());
        entity.setTowerNumber(param.getNeuralNetwork().getTowerNumber());
        entity.setTowerHeight(param.getNeuralNetwork().getTowerHeight());

        return entity;
    };
    public BridgeIdentifyCae buildEntityIdentifyCae(BridgeAddReq param){
        BridgeIdentifyCae entity=new BridgeIdentifyCae();

        BridgeAddReq.IdentifyCaeData identifyCae = param.getIdentifyCae();


        entity.setBridgeLength(identifyCae.getBridgeLength());
        entity.setSpanArrangement(identifyCae.getSpanArrangement());

        entity.setColumnNumSpan(identifyCae.getColumnNumSpan());
        entity.setColumnHeight(identifyCae.getColumnHeight());

        entity.setBridgeWidth(identifyCae.getBridgeWidth());
        entity.setMainMaterialType(identifyCae.getMainMaterialType());
        entity.setSingleBeamInterfaceType(identifyCae.getSingleBeamInterfaceType());
        entity.setConstructionYear(identifyCae.getConstructionYear());

        entity.setStiffeningGirderMaterialType(identifyCae.getStiffeningGirderMaterialType());
        entity.setStiffeningGirderSectionType(identifyCae.getStiffeningGirderSectionType());
        entity.setInclinedCableFaceNumber(identifyCae.getInclinedCableFaceNumber());
        entity.setSingleSideFaceInclinedCableNumber(identifyCae.getSingleSideFaceInclinedCableNumber());
        entity.setMainTowerVerticalShape(identifyCae.getMainTowerVerticalShape());
        entity.setMainTowerHorizontalShape(identifyCae.getMainTowerHorizontalShape());
        entity.setMainTowerFloorUpperLowerHeightRatio(identifyCae.getMainTowerFloorUpperLowerHeightRatio());
        entity.setMainTowerFloorUpperHeight(identifyCae.getMainTowerFloorUpperHeight());
        entity.setAuxiliaryPierNumber(identifyCae.getAuxiliaryPierNumber());

        return entity;
    };

    public BridgeMonitorAnalysis buildEntityMonitorAnalysis(BridgeAddReq param){
        BridgeMonitorAnalysis entity=new BridgeMonitorAnalysis();
        BridgeAddReq.MonitorAnalysisData analysis = param.getMonitorAnalysis();

        entity.setSensorSamplingFrequency(analysis.getSensorSamplingFrequency());
        entity.setMeasurementSampleNumber(analysis.getMeasurementSampleNumber());
        entity.setSampleType(analysis.getSampleType());
        entity.setMeasurementSampleIds(analysis.getMeasurementSampleIds());
        entity.setEpscCode(analysis.getEpscCode());

        return entity;
    };


    public Map<String,Object> buildPostParamNeuralNetwork(BridgeNeuralNetwork neuralNetwork){
        Map<String,Object> params=new HashMap<>();

        addMapParam(params,"mainSpan",neuralNetwork.getMainSpan());
        addMapParam(params,"girderType", neuralNetwork.getGirderType());
        addMapParam(params,"mainBeamType",neuralNetwork.getMainBeamType());
        addMapParam(params,"towerNumber",neuralNetwork.getTowerNumber());
        addMapParam(params,"towerHeight",neuralNetwork.getTowerHeight());
        return params;
    }

    public Map<String,Object> buildPostParamIdentifyCae(BridgeIdentifyCae identifyCae){
        Map<String,Object> params=new HashMap<>();

        addMapParam(params,"spans",identifyCae.getSpanArrangement());
        addMapParam(params,"width",identifyCae.getBridgeWidth());

        addMapParam(params,"bridge_year",identifyCae.getConstructionYear());
        addMapParam(params,"main_material_type",identifyCae.getMainMaterialType());
        addMapParam(params,"beam_type",identifyCae.getSingleBeamInterfaceType());

        addMapParam(params,"girder_type",identifyCae.getStiffeningGirderSectionType());
        addMapParam(params,"girder_mat",identifyCae.getStiffeningGirderMaterialType());

        addMapParam(params,"cable_plane_num",identifyCae.getInclinedCableFaceNumber());
        addMapParam(params,"cable_num",identifyCae.getSingleSideFaceInclinedCableNumber());

        addMapParam(params,"tower_vertical_type",identifyCae.getMainTowerVerticalShape());
        addMapParam(params,"tower_horizontal_type",identifyCae.getMainTowerHorizontalShape());
        addMapParam(params,"tower_h_ratio",identifyCae.getMainTowerFloorUpperLowerHeightRatio());
        addMapParam(params,"tower_h_1",identifyCae.getMainTowerFloorUpperHeight());

        addMapParam(params,"auxi_col_num",identifyCae.getAuxiliaryPierNumber());
        //立柱的信息
        addMapParam(params,"column_num",identifyCae.getColumnNumSpan());
        addMapParam(params,"column_h",identifyCae.getColumnHeight());

        return params;
    }

    public Map<String,Object> buildPostParamMonitorAnalysis(BridgeMonitorAnalysis monitorAnalysis){
        Map<String,Object> params=new HashMap<>();

        addMapParam(params,"sample_type",monitorAnalysis.getSampleType());
        addMapParam(params,"sample_frequency",monitorAnalysis.getSensorSamplingFrequency());
        addMapParam(params,"epsg",monitorAnalysis.getEpscCode());
        return params;
    }


    public void addMapParam( Map<String,Object> params,String key,Object value){
        if(Objects.isNull(value)){
            return;
        }
        params.put(key,value);
    }
}
